﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Bll;
using AspNetCs.Model;
using AspNetCs.Common;
using AspNetCs.Config;
using System.Data;
using System.Data.SqlClient;
using AspNetCs.Enumerations;

public partial class Master_Admin_ManageAncestralHall : Admin_BasePage
{
    protected City city = new City();
    AncestralHallBLL bll = AncestralHall_Bll.CreatNew;
    protected void Page_Load(object sender, EventArgs e)
    {
        IsExitAgent();
        if (!IsPostBack)
        {
            dataBind();
        }

    }



    protected void dataBind()
    {
        string cmdText = "select *,CreateName=(select UserName from Users where Userid=CreateId) from AncestralHall where IsDel=0  and province=" + AgentInfo.LoginPro + " and city=" + AgentInfo.LoginCity + " order by id desc";
        AspNetCs.Common.DataPagesOperate operate = new DataPagesOperate();

        operate.BindRepeater(cmdText, AspNetPager1, "id desc", "id", rptNetMuList);


    }


    protected void rptNetMuList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        LinkButton lbtn = null;
        try
        {
            int count = 0;
            string id = "";
            int NetMuId = 0;
            if (e.CommandName == "Modify")
            {
                lbtn = e.Item.FindControl("btn_modify") as LinkButton;
                id = lbtn.CommandArgument;
                NetMuId = Convert.ToInt32(id);
                int Istrodution = 0;
                if (lbtn.Text == "推荐")
                {
                    Istrodution = 1;
                }
                else if (lbtn.Text == "取消")
                {
                    Istrodution = 0;
                }
                bll.SetIntro(NetMuId, Istrodution);
                dataBind();

            }
            else if (e.CommandName == "delete")
            {
                lbtn = e.Item.FindControl("btn_del") as LinkButton;
                id = lbtn.CommandArgument;
                NetMuId = Convert.ToInt32(id);
                bool bo = false;

                count = bll.Delete(NetMuId);
                bo = count > 0 ? true : false;
                if (bo)
                {
                    showMessage("deleteSucce", "删除成功");
                    dataBind();
                }
                else
                {
                    showMessage("deleteFaith", "删除失败");
                    dataBind();
                }
            }
            else if (e.CommandName == "check")
            {
                lbtn = e.Item.FindControl("lbtnCheck") as LinkButton;
                id = lbtn.CommandArgument;
                NetMuId = Convert.ToInt32(id);
                bool bo = false;
                int IsCheck = 0;
                if (lbtn.Text == "审核")
                {
                    IsCheck = 1;
                }
                else if (lbtn.Text == "取消")
                {
                    IsCheck = 0;
                }
                count = bll.SetCheck(NetMuId, IsCheck);
                dataBind();
            }
        }
        catch (Exception ex)
        {
            new CustomException(ex);
        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        dataBind();
    }
}
